﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using RouteOptimization.ModelObjects;

namespace RouteOptimization.Web.Admin.Models
{
    public class RouteOptimizationModel : DbContext
    {
        public RouteOptimizationModel():base("DefaultConnection")
        {
            
        }

        public DbSet<Vertex> Vertices { get; set; }

        public DbSet<Route> Routes { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Vertex>().ToTable("Vertices");
            modelBuilder.Entity<Vertex>().HasKey(x => x.Id);
            modelBuilder.Entity<Vertex>().Property(x => x.Id).HasDatabaseGeneratedOption(
                DatabaseGeneratedOption.Identity);
            modelBuilder.Entity<Vertex>().Property(x => x.Title).IsRequired();

            modelBuilder.Entity<Route>().ToTable("Routes");
            modelBuilder.Entity<Route>().Property(x => x.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            modelBuilder.Entity<Route>().HasKey(x => x.Id);
            modelBuilder.Entity<Route>().Property(x => x.Title).IsRequired();
        }
    }
}